Add functions for adding to replacement alists
authorjustbur <justin@burkett.cc>
Thu, 9 Jul 2015 13:38:45 +0000 (09:38 -0400)
committerjustbur <justin@burkett.cc>
Thu, 9 Jul 2015 13:38:45 +0000 (09:38 -0400)
which-key.el

index 49f1f4f6b0bb1158b9fecc87a04d12d50973f8ed..5c3f4214c4a1f9dcb8a0566ba3d881a58824f239 100644 (file)
@@ -160,6 +160,9 @@ Used when `which-key-popup-type' is frame.")
     (setq-local mode-line-format nil))
   (setq which-key--setup-p t))
 
+;; Default configuration functions for use by users. Should be the "best"
+;; configurations
+
 ;;;###autoload
 (defun which-key/setup-side-window-right ()
   "Apply suggested settings for side-window that opens on right."
@@ -196,6 +199,37 @@ bottom."
   "Deactivate idle timer."
   (when which-key--open-timer (cancel-timer which-key--open-timer)))
 
+;; Helper functions to modify replacement lists.
+
+(defun which-key//add-key-based-replacements (alist key repl &rest more)
+  (while key
+    (when (or (not (stringp key)) (not (stringp repl)))
+      (error "KEY and REPL should be strings"))
+    (cl-pushnew (cons key repl) alist
+                :test (lambda (x y) (string-equal (car x) (car y))))
+    (setq key (pop more)
+          repl (pop more)))
+  alist)
+
+(defun which-key/add-key-based-replacements (key repl &rest more)
+  ;; TODO: Make interactive
+  (setq which-key-key-based-description-replacement-alist
+        (which-key//add-key-based-replacements
+         which-key-key-based-description-replacement-alist key repl more)))
+
+(defun which-key/add-major-mode-key-based-replacements (mode key repl &rest more)
+  ;; TODO: Make interactive
+  (when (not (symbolp mode))
+    (error "MODE should be a symbol corresponding to a value of major-mode"))
+  (let ((mode-alist (car (assq which-key-key-based-description-replacement-alist))))
+    (setq mode-alist (which-key//add-key-based-replacements
+                      mode-alist key repl more)
+          which-key-key-based-description-replacement-alist
+          (delq mode which-key-key-based-description-replacement-alist)
+          which-key-key-based-description-replacement-alist
+          (push mode-alist
+                which-key-key-based-description-replacement-alist))))
+
 ;; Update
 
 (defun which-key/update ()